﻿using System;
using System.Reflection;
using JetBrains.Annotations;
using NUnit.Framework;
using Assume = DiffLib.QA.Assume;

namespace DiffLib.Tests.QA
{
    [TestFixture]
    public class PublicAPITests : QualityTestsBase
    {
        [Test]
        [TestCaseSource("AllPublicTypes")]
        public void PublicTypes_ShouldBeTaggedWithPublicAPIAttribute(Type publicType)
        {
            Assert.That(publicType.IsDefined(typeof(PublicAPIAttribute), false), Is.True, "Public type " + publicType.FullName + " is not tagged with [PublicAPI]");
        }

        [Test]
        [TestCaseSource("AllPublicConstructors")]
        public void PublicConstructors_ShouldBeTaggedWithPublicAPIAttribute(ConstructorInfo publicConstructor)
        {
            Type declaringType = publicConstructor.DeclaringType;
            Assume.That(declaringType != null);
            Assert.That(publicConstructor.IsDefined(typeof(PublicAPIAttribute), false), Is.True, "Public constructor " + publicConstructor.Name + " of type " + declaringType.FullName + " is not tagged with [PublicAPI]");
        }

        [Test]
        [TestCaseSource("AllPublicMethods")]
        public void PublicMethods_ShouldBeTaggedWithPublicAPIAttribute(MethodInfo publicMethod)
        {
            Type declaringType = publicMethod.DeclaringType;
            Assume.That(declaringType != null);
            Assert.That(publicMethod.IsDefined(typeof(PublicAPIAttribute), false), Is.True, "Public method " + publicMethod.Name + " of type " + declaringType.FullName + " is not tagged with [PublicAPI]");
        }

        [Test]
        [TestCaseSource("AllPublicProperties")]
        public void PublicProperties_ShouldBeTaggedWithPublicAPIAttribute(PropertyInfo publicProperty)
        {
            Type declaringType = publicProperty.DeclaringType;
            Assume.That(declaringType != null);
            Assert.That(publicProperty.IsDefined(typeof(PublicAPIAttribute), false), Is.True, "Public property " + publicProperty.Name + " of type " + declaringType.FullName + " is not tagged with [PublicAPI]");
        }
    }
}
